import { StoreOptions } from 'vuex';
import AccessEnum from '@/access/accessEnum';
import { UserControllerService } from '../../generated';

export default {
  namespaced: true,
  state: () => ({
    loginUser: {
      userName: '未登录1'
    }
  }),
  actions: {
    async getLoginUser({ commit, state }, payload) {
      // todo 改成从远程请求登录信息
      const res = await UserControllerService.getLoginUserUsingGet();
      console.log('1', JSON.stringify(res.data));
      if (res.code === 0) {
        console.log('2');
        commit('updateUser', res.data);
      } else {
        commit('updateUser', {
          ...state.loginUser,
          userRole: AccessEnum.NOT_LOGIN
        });
      }
    }
  },
  mutations: {
    updateUser(state, payload) {
      state.loginUser = payload;
    }
  }
} as StoreOptions<any>;
